home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)axis.c V1.15 3/13/95";
- #endif
- /*
- | file -- axis.c
- |====================================================================
- |
- | This program exercises the VUax* routines by drawing axes in a
- | variety of orientations. It sleeps between views and then
- | quits.
- |
- | This program expects the name of a display device.
- |
- |=====================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc, scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvaxis.h" /* constants used by VUax routines */
- #include "dvtypes.h" /* other types for axis and tick routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "GRfundecl.h" /* GR routines (interface to display device) */
- #include "VUfundecl.h" /* VU routines (utility) */
-
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "axis.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
-
- /* Global forward function declarations */
-
- /* Local forward function declarations */
- LOCAL void LabelFunction V_P_ ((int *argp, double *valuep,
- ADDRESS labelp, TIC_DATA *tdp));
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name */
- char *device_name = DVDEVICE; /* default device name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
-
- int i, j, /* loop counters */
- direction = 1, /* direction of the axis */
- Textsize, /* size of text used */
- Labelside, /* side to display labels */
- Tickside; /* side to display tick marks */
- DV_POINT start, /* starting point of axis */
- end; /* ending point of axis */
- AXISDESC axis; /* axis data structure */
- int argc = 0;
- char **argv;
-
-
- make_argv(&argc,&argv,GetCommandLine());
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- TInit (DVPATH, DISPFORMS_STB);
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- * TscErase: Erase the entire screen in the default
- * background color
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_WINDOW_NAME, "axis.c",
- V_X_EXPOSURE_BLOCK, YES, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
- TscErase( screen );
- Sleep( 1000 );
-
- /* Loop through 16 axis orientation/layout combinations */
- for (i = 1; i <= 16; i++)
- {
-
- Textsize = 1 + (i & 1);
-
- /* Define the axis direction */
- switch (i % 4)
- {
- case AXIS_RIGHT:
- direction = AXIS_RIGHT;
- break;
-
- case AXIS_UP:
- direction = AXIS_UP;
- break;
-
- case AXIS_LEFT:
- direction = AXIS_LEFT;
- break;
-
- default:
- direction = AXIS_DOWN;
- break;
- }
-
- /*
- * Define the side of axis which the ticks will be placed
- * Default is left for axis up; right for axis right.
- */
- if (i & 4)
- Tickside = LEFT_SIDE;
- else
- Tickside = RIGHT_SIDE;
-
- /*
- * VUaxCreate: Creates and returns an axis descriptor
- * Start and end value are passed.
- */
- axis = (AXISDESC) VUaxCreate ((double) 0, (double) 10);
-
- switch (direction)
- {
- case AXIS_RIGHT:
- start.x = 50;
- start.y = 100;
- end.x = 350;
- end.y = 100;
- Labelside = RIGHT_SIDE;
- break;
-
- case AXIS_LEFT:
- start.x = 350;
- start.y = 100;
- end.x = 50;
- end.y = 100;
- Labelside = LEFT_SIDE;
- break;
-
- case AXIS_UP:
- start.x = 100;
- start.y = 50;
- end.x = 100;
- end.y = 350;
- Labelside = LEFT_SIDE;
- break;
-
- case AXIS_DOWN:
- start.x = 100;
- start.y = 350;
- end.x = 100;
- end.y = 50;
- Labelside = RIGHT_SIDE;
- break;
- }
-
- /*
- * VUaxSet: Set axis descriptor attribute fields
- */
- VUaxSet (axis,
- AXIS_DIRECTION, direction,
- AXIS_LENGTH, (int)300,
- AXIS_START_POINT, &start,
- DRAW_GRID, (int)YES,
- GRID_LENGTH, (int)300,
- GRID_LINE_TYPE, (int)2,
- LABEL_FUNCTION, LabelFunction, (ADDRESS) NULL,
- LABEL_TEXTSIZE, Textsize,
- LABEL_SIDE, Labelside,
- TICK_SIDE, Tickside,
- V_END_OF_LIST);
-
- /*
- * GRmove_and_vector: Draws a vector between two points
- */
- GRmove_and_vector (&start, &end);
-
- /* Draw the axis incrementally, a section at a time */
- /* (VUaxDraw would draw the whole axis at once.) */
- for (j = 0; j < 10; j++)
- {
- /*
- * VUaxSet: Sets axis descriptor attribute fields.
- * AXIS_NEW_START_VALUE - New start value of axis.
- */
- if (j == 5)
- VUaxSet (axis, AXIS_NEW_START_VALUE, 10.0, V_END_OF_LIST);
-
- /*
- * VUaxDrawRange: Draws a portion of the axis, which
- * is determined by the given start
- * and end value.
- */
- if (j == 4 || j == 9)
- VUaxDrawRange (axis, (double) j * 2, (double) (j * 2 + 2));
- else
- VUaxDrawRange (axis, (double) j * 2, (double) (j * 2 + 2));
- }
-
- /*
- * VUaxDestroy: Destroys an axis descriptor, freeing its memory
- * GRflush: Flushes display buffers
- * TscErase: Erase the entire screen in the default
- * background color
- */
- VUaxDestroy (axis);
- GRflush ();
- Sleep (2000);
- TscErase (screen);
- }
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the entire screen in the default
- * background color
- * TscClose: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- TscClose (screen);
- TTerminate ();
- return EXIT_OK;
- }
-
- /*-------------------------------------------------------------*/
- /* This function formats the tick value into a suitable string */
- /*ARGSUSED*/
- LOCAL void
- LabelFunction (argp, valuep, labelp, tdp)
- int *argp;
- double *valuep;
- ADDRESS labelp;
- TIC_DATA *tdp;
- {
- union
- {
- ADDRESS alias;
- LABEL_SIZE *size;
- char *label;
- } label_info;
-
- label_info.alias = labelp;
-
- /*
- * when valuep is NULL, labelp is a LABEL_SIZE * parameter,
- * and will receive information about the tick labels;
- * when valuep is non-NULL, labelp is a char* parameter, and
- * will receive the label corresponding to the valuep value.
- */
- if (valuep == NULL)
- {
- /* Return a size report, indicating how big a label will be */
- label_info.size->StringLength = 13;
- label_info.size->NumLines = 2;
- label_info.size->LongestLine = 6;
- }
- else
- {
- /* Format a label string */
- sprintf (label_info.label, "%6.2f\nmeters", *valuep);
- }
- }
-